package com.qf.controller;

import com.qf.pojo.Goods;
import com.qf.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author bss
 * @version V1.0
 * @Project maven
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/10/3 14:05
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    @RequestMapping("/getGoodsById")
    public ModelAndView getGoodsById(@RequestParam(value = "id") Integer id, ModelAndView view){
        Goods byId = goodsService.findById(id);
        if (byId==null){
            view.setViewName("redirect:/index.jsp");
            return view;
        }
        view.addObject("goods",byId);
        view.setViewName("forward:/goodsDetail.jsp");
        return view;
    }
}
